package com.elangzhi.ssm.modules.orderFrom.controller;

import com.elangzhi.ssm.controller.AdminBaseController;
import com.elangzhi.ssm.controller.util.ParamMap;
import com.elangzhi.ssm.model.Goods;
import com.elangzhi.ssm.model.OrderFrom;
import com.elangzhi.ssm.model.Shop;
import com.elangzhi.ssm.modules.orderFrom.services.OrderFromService;
import com.elangzhi.ssm.tools.Const;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
* 订单 Controller
* @author GaoXiang
* @version 1.0
*/
@Controller
@RequestMapping("/orderFrom")
public class OrderFromController extends AdminBaseController<OrderFrom> {



    /**
     * 获取我的商品列表 分页
     * 默认第一页，每页指定行数
     * @param request 请求参数
     * @return 实体列表
     * @throws Exception 获取实体列表失败
     */
    @RequestMapping(value="/myList")
    public ModelAndView myList(HttpServletRequest request, HttpSession session,Integer page,Integer size) throws Exception {
        if(page == null || page == 0){
            page = 1;
            size = 10;
        }
        ParamMap paramMap = new ParamMap(request);
        paramMap.put("shopId",findShop(session));
        PageInfo<OrderFrom> pageInfo =  orderFromService.list(paramMap,page,size);
        paramMap.put("pageInfo",pageInfo);
        return new ModelAndView("admin/orderFrom/list",paramMap);
    }

    private Object findShop(HttpSession session) {
        try {

            Shop shop = (Shop) session.getAttribute(Const.SHOP);
            if(shop == null) return null;
            return shop.getId();
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("获取session - shop 失败");
            return null;
        }
    }


    //---------------------------- property -------------------------------

    @Resource
    private OrderFromService orderFromService;

}
